package org.dromara.quick.chat.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.wukong.dto.ChannelCreateOrUpdateDTO;
import org.dromara.common.wukong.service.ChannelService;
import org.dromara.quick.chat.domain.ImChannel;
import org.dromara.quick.chat.mapper.ImChannelMapper;
import org.dromara.quick.chat.service.ImChannelService;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Arrays;

/**
 * 频道表
* @author Stars
* @description 针对表【im_channel(频道表，用于记录不同类型频道的相关信息)】的数据库操作Service实现
* @createDate 2025-03-04 22:33:21
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class ImChannelServiceImpl extends ServiceImpl<ImChannelMapper, ImChannel>
    implements ImChannelService{

    private final ImChannelMapper imChannelMapper;

    private final ChannelService channelService;


    @Override
    public void createChannel(ImChannel imChannel,Long userId) throws IOException {
        log.info("开始处理群频道，频道也是群id为：{}",imChannel.getChannelId());
        imChannelMapper.insert(imChannel);
        log.info("数据已经添加到频道表中，频道也是群id为：{}",imChannel.getChannelId());
        log.info("开始发送请求给悟空Im创建群频道，频道id为：{}",imChannel.getChannelId());
        ChannelCreateOrUpdateDTO channelCreateOrUpdateDTO = new ChannelCreateOrUpdateDTO();
        channelCreateOrUpdateDTO.setChannelId(imChannel.getChannelId());
        channelCreateOrUpdateDTO.setChannelType(imChannel.getChannelType());
        channelCreateOrUpdateDTO.setBan(imChannel.getIsBanned());
        channelCreateOrUpdateDTO.setSubscribers(Arrays.asList(userId.toString()));
        channelService.createOrUpdateChannel(channelCreateOrUpdateDTO);
        log.info("发送请求给悟空Im创建群频道成功，频道id为：{}",imChannel.getChannelId());
    }
}




